
#ifdef USE_CAIRO


#include "LuaPaint.h"

namespace LuaGui {
	Paint* LuaPaint::GetPaint() {
		return GetApplication()->GetPaint();
	}

	void LuaPaint::DrawPoint(double x, double y)
	{
		GetPaint()->DrawPoint(x, y);
	}

	void LuaPaint::Fill()
	{
		GetPaint()->Fill();
	}

	void LuaPaint::Stroke()
	{
		GetPaint()->Stroke();
	}

	void LuaPaint::MoveTo(double x, double y)
	{
		GetPaint()->MoveTo(x, y);
	}

	void LuaPaint::LineTo(double x, double y)
	{
		GetPaint()->MoveTo(x, y);
	}

	void LuaPaint::DrawLine(double x1, double y1, double x2, double y2, bool stroke)
	{
		GetPaint()->DrawLine(x1, y1, x2, y2, stroke);
	}

	void LuaPaint::DrawTriangle(double x1, double y1, double x2, double y2, double x3, double y3, bool fill, bool stroke)
	{
		GetPaint()->DrawTriangle(x1, y1, x2, y2, x3, y3, fill, stroke);
	}

	void LuaPaint::DrawCurve(double x1, double y1, double x2, double y2, double x3, double y3, bool fill, bool stroke)
	{
		GetPaint()->DrawCurve(x1, y1, x2, y2, x3, y3, fill, stroke);
	}

	void LuaPaint::DrawRectangle(double x, double y, double w, double h, bool fill, bool stroke)
	{
		GetPaint()->DrawRectangle(x, y, w, h, fill, stroke);
	}

	void LuaPaint::DrawArc(double cx, double cy, double radius, double angle1, double angle2, bool fill, bool stroke)
	{
		GetPaint()->DrawArc(cx, cy, radius, angle1 * (M_PI / 180.0), angle2 * (M_PI / 180.0), fill, stroke);
	}

	void LuaPaint::DrawPolygon(std::vector<double> points, bool fill, bool stroke)
	{
		GetPaint()->DrawPolygon(points, fill, stroke);
	}

	void LuaPaint::DrawText(double x, double y, double w, double h, const char* utf8, const int x_align, const int y_align, bool is_clip)
	{
		GetPaint()->DrawText(x, y, w, h, utf8, x_align, y_align, is_clip);
	}

	double LuaPaint::GetTextWidth(const char* text, double font_size)
	{
		return GetPaint()->GetTextWidth(text, font_size);
	}

	//int LuaPaint::GetTextWidthHeight(lua_State* L)
	//{
	//	const char* text = luabridge::Stack<const char*>::get(L, 1);
	//	double size = luabridge::Stack<double>::get(L, 2);
	//	const char* weight = luabridge::Stack<const char*>::get(L, 3);
	//	const char* slant = luabridge::Stack<const char*>::get(L, 4);
	//	const char* family = luabridge::Stack<const char*>::get(L, 5);
	//	double width = 0;
	//	double height = 0;
	//	GetPaint()->GetTextWidthHeight(text, size, weight, slant, family, &width, &height);
	//	luabridge::push(L, width);
	//	luabridge::push(L, height);
	//	return 2;
	//}

	void LuaPaint::DrawNineImage(double x, double y, double w, double h, const char* utf8_png_filename, double l, double t, double r, double b)
	{
		GetPaint()->DrawNineImage(x, y, w, h, utf8_png_filename, l, t, r, b);
	}

	void LuaPaint::DrawImage(double x, double y, double w, double h, const char* utf8_png_filename, bool is_scale)
	{
		GetPaint()->DrawImage(x, y, w, h, utf8_png_filename, 0, 0, -1, -1, is_scale);
	}

	void LuaPaint::SetPenColor(unsigned int color)
	{
		GetPaint()->SetPenColor(color);
	}

	void LuaPaint::SetLineWidth(unsigned int line_width)
	{
		GetPaint()->SetLineWidth(line_width);
	}

	void LuaPaint::SetBrushColor(unsigned int color)
	{
		GetPaint()->SetBrushColor(color);
	}

	void LuaPaint::SetFontSize(unsigned int font_size)
	{
		GetPaint()->SetFontSize(font_size);
	}

	void LuaPaint::SetFontColor(unsigned int color)
	{
		GetPaint()->SetFontColor(color);
	}

	void LuaPaint::Translate(double tx, double ty)
	{
		GetPaint()->Translate(tx, ty);
	}

	void LuaPaint::Scale(double sx, double sy)
	{
		GetPaint()->Scale(sx, sy);
	}

	void LuaPaint::Rotate(double angle)
	{
		GetPaint()->Rotate(angle);
	}

	void LuaPaint::Clip()
	{
		GetPaint()->Clip();
	}

	void LuaPaint::Save()
	{
		GetPaint()->Save();
	}

	void LuaPaint::Restore()
	{
		GetPaint()->Restore();
	}

	void LuaPaint::Clear()
	{
		GetPaint()->Clear();
	}

	void LuaPaint::Flush()
	{
		GetPaint()->Flush();
	}


	void LuaPaint::Register(lua_State* L)
	{
		luabridge::getGlobalNamespace(L)
			.beginNamespace("LuaGui")
			.beginNamespace("Paint")
			.addFunction("DrawPoint", LuaPaint::DrawPoint)
			.addFunction("MoveTo", LuaPaint::MoveTo)
			.addFunction("LineTo", LuaPaint::LineTo)
			.addFunction("Stroke", LuaPaint::Stroke)
			.addFunction("Fill", LuaPaint::Fill)
			.addFunction("DrawLine", LuaPaint::DrawLine)
			.addFunction("DrawTriangle", LuaPaint::DrawTriangle)
			.addFunction("DrawCurve", LuaPaint::DrawCurve)
			.addFunction("DrawRectangle", LuaPaint::DrawRectangle)
			.addFunction("DrawArc", LuaPaint::DrawArc)
			.addFunction("DrawPolygon", LuaPaint::DrawPolygon)
			.addFunction("DrawText", LuaPaint::DrawText)
			.addFunction("DrawNineImage", LuaPaint::DrawNineImage)
			.addFunction("DrawImage", LuaPaint::DrawImage)
			.addFunction("SetPenColor", LuaPaint::SetPenColor)
			.addFunction("SetLineWidth", LuaPaint::SetLineWidth)
			.addFunction("SetBrushColor", LuaPaint::SetBrushColor)
			.addFunction("SetFontSize", LuaPaint::SetFontSize)
			.addFunction("SetFontColor", LuaPaint::SetFontColor)
			.addFunction("Translate", LuaPaint::Translate)
			.addFunction("Scale", LuaPaint::Scale)
			.addFunction("Rotate", LuaPaint::Rotate)
			.addFunction("Clip", LuaPaint::Clip)
			.addFunction("Save", LuaPaint::Save)
			.addFunction("Restore", LuaPaint::Restore)
			.addFunction("Clear", LuaPaint::Clear)
			.addFunction("Flush", LuaPaint::Flush)
			.addFunction("GetTextWidth", LuaPaint::GetTextWidth)
			.endNamespace()
			.endNamespace();
	}

}

#endif // USE_CAIRO
